from includes import *
from Gui.GuiToolbar import *
from Gui.GuiBtn import *
from Gui.GuiTxt import *
from Gui.GuiImgFromSurface import *
from drawGalaxy import *

class MainGameGui:
    
    def __init__(self, gui_, galaxy_):
        self.screen = pygame.display.get_surface()
        screenW = self.screen.get_width()
        screenH = self.screen.get_height()
        self.galaxy = galaxy_
        self.gui = gui_
        self.toolbarTop = GuiToolbar(0,0,screenW, 25)
        self.toolbarBot = GuiToolbar(0,screenH-25,screenW, 25)
        gui_.add(self.toolbarTop)
        gui_.add(self.toolbarBot)
        self.galaxySurface = GuiImgFromSurface(0, 25, drawGalaxy(galaxy_, galaxy_.stars, 0, 0, screenW, screenH-50))
        self.galaxySurface.onClick.append(self.onGalaxyClick)
        gui_.add(self.galaxySurface)
        self.debugGalClick =  GuiTxt(15, 3, "Clicked:", "data/fonts/bitstream.ttf", 15, (255,255,255))
        gui_.add(self.debugGalClick)
        
        
    def onGalaxyClick(self, clicked_, gui_):
        mpos = pygame.mouse.get_pos()
        clickedX = (mpos[0] - clicked_.x) / (clicked_.w / self.galaxy.getWidth() )
        clickedY = (mpos[1] - clicked_.y) / (clicked_.h / self.galaxy.getHeight() )
        clickedTup = (clickedX, clickedY)
        for star in self.galaxy.stars:
            if star.pos == clickedTup:
                self.debugGalClick.text = "Clicked: " + star.name
                break
            else:
                self.debugGalClick.text = "Clicked:" + str(clickedX) + "," + str(clickedY)